//
//  SecurityEncryptTest.swift
//  HSMainViewControllerHandler
//
//  Created by haisheng huang on 2016/9/21.
//  Copyright © 2016年 haisheng huang. All rights reserved.
//

import Foundation
import UIKit



@objc open class SecurityEncryptTest: NSObject {

     static func encryptTest() -> Void {
        
        let encodeString: String = "haisheng.huang"
        let GTMBase64EncodeData: Data = GTMBase64.encode(encodeString.data(using: String.Encoding.utf8)! as Data)
        let GTMBase64EncodeDataString: String = String.init(data: GTMBase64EncodeData, encoding: String.Encoding.utf8)!
        print("GTMBase64EncodeDataString: \(GTMBase64EncodeDataString)")
        let aes256EecryptData: NSData = (GTMBase64EncodeData as NSData).aes256Encrypt(withKey: "encryptagain") as NSData
//        print("aes256EecryptData: \(aes256EecryptData)")
//        let aes256EecryptDataString: String = String.init(data: aes256EecryptData as Data, encoding: String.Encoding.utf8)!  //string 转换不了 aes256加密数据
//        print("aes256EecryptDataString: \(aes256EecryptDataString)")
        let aes256DecryptData: NSData = aes256EecryptData.aes256Decrypt(withKey: "encryptagain")! as NSData
        let aes256DecryptDataString: String = String.init(data: aes256DecryptData as Data, encoding: String.Encoding.utf8)!
        print("aes256DecryptDataString: \(aes256DecryptDataString)")
        let GTMBase64DecodeData: Data = GTMBase64.decode(aes256DecryptData as Data!)
        let GTMBase64DecodeDataString: String = String.init(data: GTMBase64DecodeData, encoding: String.Encoding.utf8)!
        print("GTMBase64DecodeDataString: \(GTMBase64DecodeDataString)")
        
        
        let stringData: Data = encodeString.data(using: String.Encoding.utf8)!
        let stringBase64Data: Data = stringData.base64EncodedData()
//        print("stringBase64Data: \(stringBase64Data)")
        let stringBase64DataString: String = String.init(data: stringBase64Data, encoding: String.Encoding.utf8)!
        print("stringBase64DataString: \(stringBase64DataString)")
        print("first change stringBase64DataString: \(stringData.base64EncodedString())") //String 原生base64加密
        print("stringBase64Data decode: \(String.init(data: Data.init(base64Encoded: stringBase64Data)!, encoding: String.Encoding.utf8)!)") //String原生解密
        
    }
    
    static func charArrayTest() -> Void {
    
        let bytes: [UInt8] = [0x52, 0x49, 0x46, 0x46, 0x26, 0x0, 0x0, 0x0, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x44, 0xac, 0x0, 0x0, 0x88, 0x58, 0x1, 0x0, 0x2, 0x0, 0x10, 0x0, 0x64, 0x61, 0x74, 0x61, 0x2, 0x0, 0x0, 0x0, 0xfc, 0xff]
        print("bytes: \(MemoryLayout.size(ofValue: bytes))")
        print("bytes: \(bytes.count)")
        let data: NSData = NSData(bytes: bytes, length: bytes.count)
        print(data);

    }
    
}
